// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryDsl;

[JsonConverter(typeof(QueryConverter))]
public sealed partial class Query
{
	internal Query(string variantName, SearchQuery variant)
	{
		if (variantName is null)
			throw new ArgumentNullException(nameof(variantName));
		if (variant is null)
			throw new ArgumentNullException(nameof(variant));
		if (string.IsNullOrWhiteSpace(variantName))
			throw new ArgumentException("Variant name must not be empty or whitespace.");
		VariantName = variantName;
		Variant = variant;
	}

	internal object Variant { get; private set; }
	internal string VariantName { get; private set; }

	internal void WrapVariant(string variantName, SearchQuery variant)
	{
		VariantName = variantName;
		Variant = variant;
	}

	public static Query Bool(Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery boolQuery) => new Query("bool", boolQuery);
	public static Query Boosting(Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery boostingQuery) => new Query("boosting", boostingQuery);
	public static Query CombinedFields(Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery combinedFieldsQuery) => new Query("combined_fields", combinedFieldsQuery);
	public static Query ConstantScore(Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery constantScoreQuery) => new Query("constant_score", constantScoreQuery);
	public static Query DisMax(Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery disMaxQuery) => new Query("dis_max", disMaxQuery);
	public static Query Exists(Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery existsQuery) => new Query("exists", existsQuery);
	public static Query FieldMaskingSpan(Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery spanFieldMaskingQuery) => new Query("field_masking_span", spanFieldMaskingQuery);
	public static Query FunctionScore(Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery functionScoreQuery) => new Query("function_score", functionScoreQuery);
	public static Query Fuzzy(Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery fuzzyQuery) => new Query("fuzzy", fuzzyQuery);
	public static Query GeoBoundingBox(Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery geoBoundingBoxQuery) => new Query("geo_bounding_box", geoBoundingBoxQuery);
	public static Query GeoDistance(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery geoDistanceQuery) => new Query("geo_distance", geoDistanceQuery);
	public static Query GeoPolygon(Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonQuery geoPolygonQuery) => new Query("geo_polygon", geoPolygonQuery);
	public static Query HasChild(Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery hasChildQuery) => new Query("has_child", hasChildQuery);
	public static Query HasParent(Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery hasParentQuery) => new Query("has_parent", hasParentQuery);
	public static Query Ids(Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery idsQuery) => new Query("ids", idsQuery);
	public static Query Intervals(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery intervalsQuery) => new Query("intervals", intervalsQuery);
	public static Query Match(Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery matchQuery) => new Query("match", matchQuery);
	public static Query MatchAll(Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery matchAllQuery) => new Query("match_all", matchAllQuery);
	public static Query MatchBoolPrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery matchBoolPrefixQuery) => new Query("match_bool_prefix", matchBoolPrefixQuery);
	public static Query MatchNone(Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery matchNoneQuery) => new Query("match_none", matchNoneQuery);
	public static Query MatchPhrase(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery matchPhraseQuery) => new Query("match_phrase", matchPhraseQuery);
	public static Query MatchPhrasePrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery matchPhrasePrefixQuery) => new Query("match_phrase_prefix", matchPhrasePrefixQuery);
	public static Query MoreLikeThis(Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery moreLikeThisQuery) => new Query("more_like_this", moreLikeThisQuery);
	public static Query MultiMatch(Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery multiMatchQuery) => new Query("multi_match", multiMatchQuery);
	public static Query Nested(Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery nestedQuery) => new Query("nested", nestedQuery);
	public static Query ParentId(Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery parentIdQuery) => new Query("parent_id", parentIdQuery);
	public static Query Percolate(Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery percolateQuery) => new Query("percolate", percolateQuery);
	public static Query Pinned(Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery pinnedQuery) => new Query("pinned", pinnedQuery);
	public static Query Prefix(Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery prefixQuery) => new Query("prefix", prefixQuery);
	public static Query QueryString(Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery queryStringQuery) => new Query("query_string", queryStringQuery);
	public static Query Range(Elastic.Clients.Elasticsearch.QueryDsl.RangeQuery rangeQuery) => new Query("range", rangeQuery);
	public static Query RankFeature(Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery rankFeatureQuery) => new Query("rank_feature", rankFeatureQuery);
	public static Query RawJson(Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawJsonQuery) => new Query("raw_json", rawJsonQuery);
	public static Query Regexp(Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery regexpQuery) => new Query("regexp", regexpQuery);
	public static Query RuleQuery(Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery ruleQuery) => new Query("rule_query", ruleQuery);
	public static Query Script(Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery scriptQuery) => new Query("script", scriptQuery);
	public static Query ScriptScore(Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery scriptScoreQuery) => new Query("script_score", scriptScoreQuery);
	public static Query SimpleQueryString(Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery simpleQueryStringQuery) => new Query("simple_query_string", simpleQueryStringQuery);
	public static Query SpanContaining(Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery spanContainingQuery) => new Query("span_containing", spanContainingQuery);
	public static Query SpanFirst(Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery spanFirstQuery) => new Query("span_first", spanFirstQuery);
	public static Query SpanMulti(Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery spanMultiTermQuery) => new Query("span_multi", spanMultiTermQuery);
	public static Query SpanNear(Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery spanNearQuery) => new Query("span_near", spanNearQuery);
	public static Query SpanNot(Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery spanNotQuery) => new Query("span_not", spanNotQuery);
	public static Query SpanOr(Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery spanOrQuery) => new Query("span_or", spanOrQuery);
	public static Query SpanTerm(Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery spanTermQuery) => new Query("span_term", spanTermQuery);
	public static Query SpanWithin(Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery spanWithinQuery) => new Query("span_within", spanWithinQuery);
	public static Query Term(Elastic.Clients.Elasticsearch.QueryDsl.TermQuery termQuery) => new Query("term", termQuery);
	public static Query Terms(Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery termsQuery) => new Query("terms", termsQuery);
	public static Query TermsSet(Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery termsSetQuery) => new Query("terms_set", termsSetQuery);
	public static Query TextExpansion(Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery textExpansionQuery) => new Query("text_expansion", textExpansionQuery);
	public static Query Wildcard(Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery wildcardQuery) => new Query("wildcard", wildcardQuery);
	public static Query Wrapper(Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery wrapperQuery) => new Query("wrapper", wrapperQuery);
}

internal sealed partial class QueryConverter : JsonConverter<Query>
{
	public override Query Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		if (reader.TokenType != JsonTokenType.StartObject)
		{
			throw new JsonException("Expected start token.");
		}

		reader.Read();
		if (reader.TokenType != JsonTokenType.PropertyName)
		{
			throw new JsonException("Expected a property name token representing the variant held within this container.");
		}

		var propertyName = reader.GetString();
		reader.Read();
		if (propertyName == "bool")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "boosting")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "combined_fields")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "constant_score")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "dis_max")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "exists")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "field_masking_span")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "function_score")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "fuzzy")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "geo_bounding_box")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "geo_distance")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "geo_polygon")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "has_child")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "has_parent")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "ids")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "intervals")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "match")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "match_all")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "match_bool_prefix")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "match_none")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "match_phrase")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "match_phrase_prefix")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "more_like_this")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "multi_match")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "nested")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "parent_id")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "percolate")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "pinned")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "prefix")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "query_string")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "range")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RangeQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "rank_feature")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "raw_json")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "regexp")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "rule_query")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "script")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "script_score")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "simple_query_string")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_containing")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_first")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_multi")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_near")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_not")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_or")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_term")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "span_within")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "term")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TermQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "terms")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "terms_set")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "text_expansion")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "wildcard")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		if (propertyName == "wrapper")
		{
			var variant = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery?>(ref reader, options);
			reader.Read();
			return new Query(propertyName, variant);
		}

		throw new JsonException();
	}

	public override void Write(Utf8JsonWriter writer, Query value, JsonSerializerOptions options)
	{
		if (value.VariantName == "raw_json" && value.TryGet<RawJsonQuery>(out var rawJsonQuery))
		{
			writer.WriteRawValue(rawJsonQuery.Raw);
			return;
		}

		writer.WriteStartObject();
		if (value.VariantName is not null & value.Variant is not null)
		{
			writer.WritePropertyName(value.VariantName);
			switch (value.VariantName)
			{
				case "bool":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery)value.Variant, options);
					break;
				case "boosting":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery)value.Variant, options);
					break;
				case "combined_fields":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery)value.Variant, options);
					break;
				case "constant_score":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery)value.Variant, options);
					break;
				case "dis_max":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery)value.Variant, options);
					break;
				case "exists":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery)value.Variant, options);
					break;
				case "field_masking_span":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery)value.Variant, options);
					break;
				case "function_score":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery)value.Variant, options);
					break;
				case "fuzzy":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery)value.Variant, options);
					break;
				case "geo_bounding_box":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery)value.Variant, options);
					break;
				case "geo_distance":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery)value.Variant, options);
					break;
				case "geo_polygon":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoPolygonQuery)value.Variant, options);
					break;
				case "has_child":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery)value.Variant, options);
					break;
				case "has_parent":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery)value.Variant, options);
					break;
				case "ids":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery)value.Variant, options);
					break;
				case "intervals":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery)value.Variant, options);
					break;
				case "match":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery)value.Variant, options);
					break;
				case "match_all":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery)value.Variant, options);
					break;
				case "match_bool_prefix":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery)value.Variant, options);
					break;
				case "match_none":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery)value.Variant, options);
					break;
				case "match_phrase":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery)value.Variant, options);
					break;
				case "match_phrase_prefix":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery)value.Variant, options);
					break;
				case "more_like_this":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery)value.Variant, options);
					break;
				case "multi_match":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery)value.Variant, options);
					break;
				case "nested":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery)value.Variant, options);
					break;
				case "parent_id":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery)value.Variant, options);
					break;
				case "percolate":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery)value.Variant, options);
					break;
				case "pinned":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery)value.Variant, options);
					break;
				case "prefix":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery)value.Variant, options);
					break;
				case "query_string":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery)value.Variant, options);
					break;
				case "range":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RangeQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RangeQuery)value.Variant, options);
					break;
				case "rank_feature":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery)value.Variant, options);
					break;
				case "raw_json":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery)value.Variant, options);
					break;
				case "regexp":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery)value.Variant, options);
					break;
				case "rule_query":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery)value.Variant, options);
					break;
				case "script":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery)value.Variant, options);
					break;
				case "script_score":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery)value.Variant, options);
					break;
				case "simple_query_string":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery)value.Variant, options);
					break;
				case "span_containing":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery)value.Variant, options);
					break;
				case "span_first":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery)value.Variant, options);
					break;
				case "span_multi":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery)value.Variant, options);
					break;
				case "span_near":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery)value.Variant, options);
					break;
				case "span_not":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery)value.Variant, options);
					break;
				case "span_or":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery)value.Variant, options);
					break;
				case "span_term":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery)value.Variant, options);
					break;
				case "span_within":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery)value.Variant, options);
					break;
				case "term":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TermQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TermQuery)value.Variant, options);
					break;
				case "terms":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery)value.Variant, options);
					break;
				case "terms_set":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery)value.Variant, options);
					break;
				case "text_expansion":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery)value.Variant, options);
					break;
				case "wildcard":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery)value.Variant, options);
					break;
				case "wrapper":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery)value.Variant, options);
					break;
			}
		}

		writer.WriteEndObject();
	}
}

public sealed partial class QueryDescriptor<TDocument> : SerializableDescriptor<QueryDescriptor<TDocument>>
{
	internal QueryDescriptor(Action<QueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public QueryDescriptor() : base()
	{
	}

	private bool ContainsVariant { get; set; }
	private string ContainedVariantName { get; set; }
	private object Variant { get; set; }
	private Descriptor Descriptor { get; set; }

	private QueryDescriptor<TDocument> Set<T>(Action<T> descriptorAction, string variantName) where T : Descriptor
	{
		ContainedVariantName = variantName;
		ContainsVariant = true;
		var descriptor = (T)Activator.CreateInstance(typeof(T), true);
		descriptorAction?.Invoke(descriptor);
		Descriptor = descriptor;
		return Self;
	}

	private QueryDescriptor<TDocument> Set(object variant, string variantName)
	{
		Variant = variant;
		ContainedVariantName = variantName;
		ContainsVariant = true;
		return Self;
	}

	public QueryDescriptor<TDocument> Bool(BoolQuery boolQuery) => Set(boolQuery, "bool");
	public QueryDescriptor<TDocument> Bool(Action<BoolQueryDescriptor<TDocument>> configure) => Set(configure, "bool");
	public QueryDescriptor<TDocument> Boosting(BoostingQuery boostingQuery) => Set(boostingQuery, "boosting");
	public QueryDescriptor<TDocument> Boosting(Action<BoostingQueryDescriptor<TDocument>> configure) => Set(configure, "boosting");
	public QueryDescriptor<TDocument> CombinedFields(CombinedFieldsQuery combinedFieldsQuery) => Set(combinedFieldsQuery, "combined_fields");
	public QueryDescriptor<TDocument> CombinedFields(Action<CombinedFieldsQueryDescriptor<TDocument>> configure) => Set(configure, "combined_fields");
	public QueryDescriptor<TDocument> ConstantScore(ConstantScoreQuery constantScoreQuery) => Set(constantScoreQuery, "constant_score");
	public QueryDescriptor<TDocument> ConstantScore(Action<ConstantScoreQueryDescriptor<TDocument>> configure) => Set(configure, "constant_score");
	public QueryDescriptor<TDocument> DisMax(DisMaxQuery disMaxQuery) => Set(disMaxQuery, "dis_max");
	public QueryDescriptor<TDocument> DisMax(Action<DisMaxQueryDescriptor<TDocument>> configure) => Set(configure, "dis_max");
	public QueryDescriptor<TDocument> Exists(ExistsQuery existsQuery) => Set(existsQuery, "exists");
	public QueryDescriptor<TDocument> Exists(Action<ExistsQueryDescriptor<TDocument>> configure) => Set(configure, "exists");
	public QueryDescriptor<TDocument> FieldMaskingSpan(SpanFieldMaskingQuery spanFieldMaskingQuery) => Set(spanFieldMaskingQuery, "field_masking_span");
	public QueryDescriptor<TDocument> FieldMaskingSpan(Action<SpanFieldMaskingQueryDescriptor<TDocument>> configure) => Set(configure, "field_masking_span");
	public QueryDescriptor<TDocument> FunctionScore(FunctionScoreQuery functionScoreQuery) => Set(functionScoreQuery, "function_score");
	public QueryDescriptor<TDocument> FunctionScore(Action<FunctionScoreQueryDescriptor<TDocument>> configure) => Set(configure, "function_score");
	public QueryDescriptor<TDocument> Fuzzy(FuzzyQuery fuzzyQuery) => Set(fuzzyQuery, "fuzzy");
	public QueryDescriptor<TDocument> Fuzzy(Action<FuzzyQueryDescriptor<TDocument>> configure) => Set(configure, "fuzzy");
	public QueryDescriptor<TDocument> GeoBoundingBox(GeoBoundingBoxQuery geoBoundingBoxQuery) => Set(geoBoundingBoxQuery, "geo_bounding_box");
	public QueryDescriptor<TDocument> GeoBoundingBox(Action<GeoBoundingBoxQueryDescriptor<TDocument>> configure) => Set(configure, "geo_bounding_box");
	public QueryDescriptor<TDocument> GeoDistance(GeoDistanceQuery geoDistanceQuery) => Set(geoDistanceQuery, "geo_distance");
	public QueryDescriptor<TDocument> GeoDistance(Action<GeoDistanceQueryDescriptor<TDocument>> configure) => Set(configure, "geo_distance");
	public QueryDescriptor<TDocument> GeoPolygon(GeoPolygonQuery geoPolygonQuery) => Set(geoPolygonQuery, "geo_polygon");
	public QueryDescriptor<TDocument> GeoPolygon(Action<GeoPolygonQueryDescriptor<TDocument>> configure) => Set(configure, "geo_polygon");
	public QueryDescriptor<TDocument> HasChild(HasChildQuery hasChildQuery) => Set(hasChildQuery, "has_child");
	public QueryDescriptor<TDocument> HasChild(Action<HasChildQueryDescriptor<TDocument>> configure) => Set(configure, "has_child");
	public QueryDescriptor<TDocument> HasParent(HasParentQuery hasParentQuery) => Set(hasParentQuery, "has_parent");
	public QueryDescriptor<TDocument> HasParent(Action<HasParentQueryDescriptor<TDocument>> configure) => Set(configure, "has_parent");
	public QueryDescriptor<TDocument> Ids(IdsQuery idsQuery) => Set(idsQuery, "ids");
	public QueryDescriptor<TDocument> Ids(Action<IdsQueryDescriptor> configure) => Set(configure, "ids");
	public QueryDescriptor<TDocument> Intervals(IntervalsQuery intervalsQuery) => Set(intervalsQuery, "intervals");
	public QueryDescriptor<TDocument> Intervals(Action<IntervalsQueryDescriptor<TDocument>> configure) => Set(configure, "intervals");
	public QueryDescriptor<TDocument> Match(MatchQuery matchQuery) => Set(matchQuery, "match");
	public QueryDescriptor<TDocument> Match(Action<MatchQueryDescriptor<TDocument>> configure) => Set(configure, "match");
	public QueryDescriptor<TDocument> MatchAll(MatchAllQuery matchAllQuery) => Set(matchAllQuery, "match_all");
	public QueryDescriptor<TDocument> MatchAll(Action<MatchAllQueryDescriptor> configure) => Set(configure, "match_all");
	public QueryDescriptor<TDocument> MatchBoolPrefix(MatchBoolPrefixQuery matchBoolPrefixQuery) => Set(matchBoolPrefixQuery, "match_bool_prefix");
	public QueryDescriptor<TDocument> MatchBoolPrefix(Action<MatchBoolPrefixQueryDescriptor<TDocument>> configure) => Set(configure, "match_bool_prefix");
	public QueryDescriptor<TDocument> MatchNone(MatchNoneQuery matchNoneQuery) => Set(matchNoneQuery, "match_none");
	public QueryDescriptor<TDocument> MatchNone(Action<MatchNoneQueryDescriptor> configure) => Set(configure, "match_none");
	public QueryDescriptor<TDocument> MatchPhrase(MatchPhraseQuery matchPhraseQuery) => Set(matchPhraseQuery, "match_phrase");
	public QueryDescriptor<TDocument> MatchPhrase(Action<MatchPhraseQueryDescriptor<TDocument>> configure) => Set(configure, "match_phrase");
	public QueryDescriptor<TDocument> MatchPhrasePrefix(MatchPhrasePrefixQuery matchPhrasePrefixQuery) => Set(matchPhrasePrefixQuery, "match_phrase_prefix");
	public QueryDescriptor<TDocument> MatchPhrasePrefix(Action<MatchPhrasePrefixQueryDescriptor<TDocument>> configure) => Set(configure, "match_phrase_prefix");
	public QueryDescriptor<TDocument> MoreLikeThis(MoreLikeThisQuery moreLikeThisQuery) => Set(moreLikeThisQuery, "more_like_this");
	public QueryDescriptor<TDocument> MoreLikeThis(Action<MoreLikeThisQueryDescriptor<TDocument>> configure) => Set(configure, "more_like_this");
	public QueryDescriptor<TDocument> MultiMatch(MultiMatchQuery multiMatchQuery) => Set(multiMatchQuery, "multi_match");
	public QueryDescriptor<TDocument> MultiMatch(Action<MultiMatchQueryDescriptor<TDocument>> configure) => Set(configure, "multi_match");
	public QueryDescriptor<TDocument> Nested(NestedQuery nestedQuery) => Set(nestedQuery, "nested");
	public QueryDescriptor<TDocument> Nested(Action<NestedQueryDescriptor<TDocument>> configure) => Set(configure, "nested");
	public QueryDescriptor<TDocument> ParentId(ParentIdQuery parentIdQuery) => Set(parentIdQuery, "parent_id");
	public QueryDescriptor<TDocument> ParentId(Action<ParentIdQueryDescriptor> configure) => Set(configure, "parent_id");
	public QueryDescriptor<TDocument> Percolate(PercolateQuery percolateQuery) => Set(percolateQuery, "percolate");
	public QueryDescriptor<TDocument> Percolate(Action<PercolateQueryDescriptor<TDocument>> configure) => Set(configure, "percolate");
	public QueryDescriptor<TDocument> Pinned(PinnedQuery pinnedQuery) => Set(pinnedQuery, "pinned");
	public QueryDescriptor<TDocument> Pinned(Action<PinnedQueryDescriptor<TDocument>> configure) => Set(configure, "pinned");
	public QueryDescriptor<TDocument> Prefix(PrefixQuery prefixQuery) => Set(prefixQuery, "prefix");
	public QueryDescriptor<TDocument> Prefix(Action<PrefixQueryDescriptor<TDocument>> configure) => Set(configure, "prefix");
	public QueryDescriptor<TDocument> QueryString(QueryStringQuery queryStringQuery) => Set(queryStringQuery, "query_string");
	public QueryDescriptor<TDocument> QueryString(Action<QueryStringQueryDescriptor<TDocument>> configure) => Set(configure, "query_string");
	public QueryDescriptor<TDocument> Range(RangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor<TDocument> Range(Action<RangeQueryDescriptor<TDocument>> configure) => Set(configure, "range");
	public QueryDescriptor<TDocument> RankFeature(RankFeatureQuery rankFeatureQuery) => Set(rankFeatureQuery, "rank_feature");
	public QueryDescriptor<TDocument> RankFeature(Action<RankFeatureQueryDescriptor<TDocument>> configure) => Set(configure, "rank_feature");
	public QueryDescriptor<TDocument> RawJson(Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawJsonQuery) => Set(rawJsonQuery, "raw_json");
	public QueryDescriptor<TDocument> Regexp(RegexpQuery regexpQuery) => Set(regexpQuery, "regexp");
	public QueryDescriptor<TDocument> Regexp(Action<RegexpQueryDescriptor<TDocument>> configure) => Set(configure, "regexp");
	public QueryDescriptor<TDocument> RuleQuery(RuleQuery ruleQuery) => Set(ruleQuery, "rule_query");
	public QueryDescriptor<TDocument> RuleQuery(Action<RuleQueryDescriptor<TDocument>> configure) => Set(configure, "rule_query");
	public QueryDescriptor<TDocument> Script(ScriptQuery scriptQuery) => Set(scriptQuery, "script");
	public QueryDescriptor<TDocument> Script(Action<ScriptQueryDescriptor> configure) => Set(configure, "script");
	public QueryDescriptor<TDocument> ScriptScore(ScriptScoreQuery scriptScoreQuery) => Set(scriptScoreQuery, "script_score");
	public QueryDescriptor<TDocument> ScriptScore(Action<ScriptScoreQueryDescriptor<TDocument>> configure) => Set(configure, "script_score");
	public QueryDescriptor<TDocument> SimpleQueryString(SimpleQueryStringQuery simpleQueryStringQuery) => Set(simpleQueryStringQuery, "simple_query_string");
	public QueryDescriptor<TDocument> SimpleQueryString(Action<SimpleQueryStringQueryDescriptor<TDocument>> configure) => Set(configure, "simple_query_string");
	public QueryDescriptor<TDocument> SpanContaining(SpanContainingQuery spanContainingQuery) => Set(spanContainingQuery, "span_containing");
	public QueryDescriptor<TDocument> SpanContaining(Action<SpanContainingQueryDescriptor<TDocument>> configure) => Set(configure, "span_containing");
	public QueryDescriptor<TDocument> SpanFirst(SpanFirstQuery spanFirstQuery) => Set(spanFirstQuery, "span_first");
	public QueryDescriptor<TDocument> SpanFirst(Action<SpanFirstQueryDescriptor<TDocument>> configure) => Set(configure, "span_first");
	public QueryDescriptor<TDocument> SpanMulti(SpanMultiTermQuery spanMultiTermQuery) => Set(spanMultiTermQuery, "span_multi");
	public QueryDescriptor<TDocument> SpanMulti(Action<SpanMultiTermQueryDescriptor<TDocument>> configure) => Set(configure, "span_multi");
	public QueryDescriptor<TDocument> SpanNear(SpanNearQuery spanNearQuery) => Set(spanNearQuery, "span_near");
	public QueryDescriptor<TDocument> SpanNear(Action<SpanNearQueryDescriptor<TDocument>> configure) => Set(configure, "span_near");
	public QueryDescriptor<TDocument> SpanNot(SpanNotQuery spanNotQuery) => Set(spanNotQuery, "span_not");
	public QueryDescriptor<TDocument> SpanNot(Action<SpanNotQueryDescriptor<TDocument>> configure) => Set(configure, "span_not");
	public QueryDescriptor<TDocument> SpanOr(SpanOrQuery spanOrQuery) => Set(spanOrQuery, "span_or");
	public QueryDescriptor<TDocument> SpanOr(Action<SpanOrQueryDescriptor<TDocument>> configure) => Set(configure, "span_or");
	public QueryDescriptor<TDocument> SpanTerm(SpanTermQuery spanTermQuery) => Set(spanTermQuery, "span_term");
	public QueryDescriptor<TDocument> SpanTerm(Action<SpanTermQueryDescriptor<TDocument>> configure) => Set(configure, "span_term");
	public QueryDescriptor<TDocument> SpanWithin(SpanWithinQuery spanWithinQuery) => Set(spanWithinQuery, "span_within");
	public QueryDescriptor<TDocument> SpanWithin(Action<SpanWithinQueryDescriptor<TDocument>> configure) => Set(configure, "span_within");
	public QueryDescriptor<TDocument> Term(TermQuery termQuery) => Set(termQuery, "term");
	public QueryDescriptor<TDocument> Term(Action<TermQueryDescriptor<TDocument>> configure) => Set(configure, "term");
	public QueryDescriptor<TDocument> Terms(TermsQuery termsQuery) => Set(termsQuery, "terms");
	public QueryDescriptor<TDocument> Terms(Action<TermsQueryDescriptor<TDocument>> configure) => Set(configure, "terms");
	public QueryDescriptor<TDocument> TermsSet(TermsSetQuery termsSetQuery) => Set(termsSetQuery, "terms_set");
	public QueryDescriptor<TDocument> TermsSet(Action<TermsSetQueryDescriptor<TDocument>> configure) => Set(configure, "terms_set");
	public QueryDescriptor<TDocument> TextExpansion(TextExpansionQuery textExpansionQuery) => Set(textExpansionQuery, "text_expansion");
	public QueryDescriptor<TDocument> TextExpansion(Action<TextExpansionQueryDescriptor<TDocument>> configure) => Set(configure, "text_expansion");
	public QueryDescriptor<TDocument> Wildcard(WildcardQuery wildcardQuery) => Set(wildcardQuery, "wildcard");
	public QueryDescriptor<TDocument> Wildcard(Action<WildcardQueryDescriptor<TDocument>> configure) => Set(configure, "wildcard");
	public QueryDescriptor<TDocument> Wrapper(WrapperQuery wrapperQuery) => Set(wrapperQuery, "wrapper");
	public QueryDescriptor<TDocument> Wrapper(Action<WrapperQueryDescriptor> configure) => Set(configure, "wrapper");

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		if (!ContainsVariant)
		{
			writer.WriteNullValue();
			return;
		}

		if (ContainedVariantName == "raw_json")
		{
			writer.WriteRawValue(((RawJsonQuery)Variant).Raw);
			return;
		}

		writer.WriteStartObject();
		writer.WritePropertyName(ContainedVariantName);
		if (Variant is not null)
		{
			JsonSerializer.Serialize(writer, Variant, Variant.GetType(), options);
			writer.WriteEndObject();
			return;
		}

		JsonSerializer.Serialize(writer, Descriptor, Descriptor.GetType(), options);
		writer.WriteEndObject();
	}
}

public sealed partial class QueryDescriptor : SerializableDescriptor<QueryDescriptor>
{
	internal QueryDescriptor(Action<QueryDescriptor> configure) => configure.Invoke(this);

	public QueryDescriptor() : base()
	{
	}

	private bool ContainsVariant { get; set; }
	private string ContainedVariantName { get; set; }
	private object Variant { get; set; }
	private Descriptor Descriptor { get; set; }

	private QueryDescriptor Set<T>(Action<T> descriptorAction, string variantName) where T : Descriptor
	{
		ContainedVariantName = variantName;
		ContainsVariant = true;
		var descriptor = (T)Activator.CreateInstance(typeof(T), true);
		descriptorAction?.Invoke(descriptor);
		Descriptor = descriptor;
		return Self;
	}

	private QueryDescriptor Set(object variant, string variantName)
	{
		Variant = variant;
		ContainedVariantName = variantName;
		ContainsVariant = true;
		return Self;
	}

	public QueryDescriptor Bool(BoolQuery boolQuery) => Set(boolQuery, "bool");
	public QueryDescriptor Bool(Action<BoolQueryDescriptor> configure) => Set(configure, "bool");
	public QueryDescriptor Bool<TDocument>(Action<BoolQueryDescriptor<TDocument>> configure) => Set(configure, "bool");
	public QueryDescriptor Boosting(BoostingQuery boostingQuery) => Set(boostingQuery, "boosting");
	public QueryDescriptor Boosting(Action<BoostingQueryDescriptor> configure) => Set(configure, "boosting");
	public QueryDescriptor Boosting<TDocument>(Action<BoostingQueryDescriptor<TDocument>> configure) => Set(configure, "boosting");
	public QueryDescriptor CombinedFields(CombinedFieldsQuery combinedFieldsQuery) => Set(combinedFieldsQuery, "combined_fields");
	public QueryDescriptor CombinedFields(Action<CombinedFieldsQueryDescriptor> configure) => Set(configure, "combined_fields");
	public QueryDescriptor CombinedFields<TDocument>(Action<CombinedFieldsQueryDescriptor<TDocument>> configure) => Set(configure, "combined_fields");
	public QueryDescriptor ConstantScore(ConstantScoreQuery constantScoreQuery) => Set(constantScoreQuery, "constant_score");
	public QueryDescriptor ConstantScore(Action<ConstantScoreQueryDescriptor> configure) => Set(configure, "constant_score");
	public QueryDescriptor ConstantScore<TDocument>(Action<ConstantScoreQueryDescriptor<TDocument>> configure) => Set(configure, "constant_score");
	public QueryDescriptor DisMax(DisMaxQuery disMaxQuery) => Set(disMaxQuery, "dis_max");
	public QueryDescriptor DisMax(Action<DisMaxQueryDescriptor> configure) => Set(configure, "dis_max");
	public QueryDescriptor DisMax<TDocument>(Action<DisMaxQueryDescriptor<TDocument>> configure) => Set(configure, "dis_max");
	public QueryDescriptor Exists(ExistsQuery existsQuery) => Set(existsQuery, "exists");
	public QueryDescriptor Exists(Action<ExistsQueryDescriptor> configure) => Set(configure, "exists");
	public QueryDescriptor Exists<TDocument>(Action<ExistsQueryDescriptor<TDocument>> configure) => Set(configure, "exists");
	public QueryDescriptor FieldMaskingSpan(SpanFieldMaskingQuery spanFieldMaskingQuery) => Set(spanFieldMaskingQuery, "field_masking_span");
	public QueryDescriptor FieldMaskingSpan(Action<SpanFieldMaskingQueryDescriptor> configure) => Set(configure, "field_masking_span");
	public QueryDescriptor FieldMaskingSpan<TDocument>(Action<SpanFieldMaskingQueryDescriptor<TDocument>> configure) => Set(configure, "field_masking_span");
	public QueryDescriptor FunctionScore(FunctionScoreQuery functionScoreQuery) => Set(functionScoreQuery, "function_score");
	public QueryDescriptor FunctionScore(Action<FunctionScoreQueryDescriptor> configure) => Set(configure, "function_score");
	public QueryDescriptor FunctionScore<TDocument>(Action<FunctionScoreQueryDescriptor<TDocument>> configure) => Set(configure, "function_score");
	public QueryDescriptor Fuzzy(FuzzyQuery fuzzyQuery) => Set(fuzzyQuery, "fuzzy");
	public QueryDescriptor Fuzzy(Action<FuzzyQueryDescriptor> configure) => Set(configure, "fuzzy");
	public QueryDescriptor Fuzzy<TDocument>(Action<FuzzyQueryDescriptor<TDocument>> configure) => Set(configure, "fuzzy");
	public QueryDescriptor GeoBoundingBox(GeoBoundingBoxQuery geoBoundingBoxQuery) => Set(geoBoundingBoxQuery, "geo_bounding_box");
	public QueryDescriptor GeoBoundingBox(Action<GeoBoundingBoxQueryDescriptor> configure) => Set(configure, "geo_bounding_box");
	public QueryDescriptor GeoBoundingBox<TDocument>(Action<GeoBoundingBoxQueryDescriptor<TDocument>> configure) => Set(configure, "geo_bounding_box");
	public QueryDescriptor GeoDistance(GeoDistanceQuery geoDistanceQuery) => Set(geoDistanceQuery, "geo_distance");
	public QueryDescriptor GeoDistance(Action<GeoDistanceQueryDescriptor> configure) => Set(configure, "geo_distance");
	public QueryDescriptor GeoDistance<TDocument>(Action<GeoDistanceQueryDescriptor<TDocument>> configure) => Set(configure, "geo_distance");
	public QueryDescriptor GeoPolygon(GeoPolygonQuery geoPolygonQuery) => Set(geoPolygonQuery, "geo_polygon");
	public QueryDescriptor GeoPolygon(Action<GeoPolygonQueryDescriptor> configure) => Set(configure, "geo_polygon");
	public QueryDescriptor GeoPolygon<TDocument>(Action<GeoPolygonQueryDescriptor<TDocument>> configure) => Set(configure, "geo_polygon");
	public QueryDescriptor HasChild(HasChildQuery hasChildQuery) => Set(hasChildQuery, "has_child");
	public QueryDescriptor HasChild(Action<HasChildQueryDescriptor> configure) => Set(configure, "has_child");
	public QueryDescriptor HasChild<TDocument>(Action<HasChildQueryDescriptor<TDocument>> configure) => Set(configure, "has_child");
	public QueryDescriptor HasParent(HasParentQuery hasParentQuery) => Set(hasParentQuery, "has_parent");
	public QueryDescriptor HasParent(Action<HasParentQueryDescriptor> configure) => Set(configure, "has_parent");
	public QueryDescriptor HasParent<TDocument>(Action<HasParentQueryDescriptor<TDocument>> configure) => Set(configure, "has_parent");
	public QueryDescriptor Ids(IdsQuery idsQuery) => Set(idsQuery, "ids");
	public QueryDescriptor Ids(Action<IdsQueryDescriptor> configure) => Set(configure, "ids");
	public QueryDescriptor Intervals(IntervalsQuery intervalsQuery) => Set(intervalsQuery, "intervals");
	public QueryDescriptor Intervals(Action<IntervalsQueryDescriptor> configure) => Set(configure, "intervals");
	public QueryDescriptor Intervals<TDocument>(Action<IntervalsQueryDescriptor<TDocument>> configure) => Set(configure, "intervals");
	public QueryDescriptor Match(MatchQuery matchQuery) => Set(matchQuery, "match");
	public QueryDescriptor Match(Action<MatchQueryDescriptor> configure) => Set(configure, "match");
	public QueryDescriptor Match<TDocument>(Action<MatchQueryDescriptor<TDocument>> configure) => Set(configure, "match");
	public QueryDescriptor MatchAll(MatchAllQuery matchAllQuery) => Set(matchAllQuery, "match_all");
	public QueryDescriptor MatchAll(Action<MatchAllQueryDescriptor> configure) => Set(configure, "match_all");
	public QueryDescriptor MatchBoolPrefix(MatchBoolPrefixQuery matchBoolPrefixQuery) => Set(matchBoolPrefixQuery, "match_bool_prefix");
	public QueryDescriptor MatchBoolPrefix(Action<MatchBoolPrefixQueryDescriptor> configure) => Set(configure, "match_bool_prefix");
	public QueryDescriptor MatchBoolPrefix<TDocument>(Action<MatchBoolPrefixQueryDescriptor<TDocument>> configure) => Set(configure, "match_bool_prefix");
	public QueryDescriptor MatchNone(MatchNoneQuery matchNoneQuery) => Set(matchNoneQuery, "match_none");
	public QueryDescriptor MatchNone(Action<MatchNoneQueryDescriptor> configure) => Set(configure, "match_none");
	public QueryDescriptor MatchPhrase(MatchPhraseQuery matchPhraseQuery) => Set(matchPhraseQuery, "match_phrase");
	public QueryDescriptor MatchPhrase(Action<MatchPhraseQueryDescriptor> configure) => Set(configure, "match_phrase");
	public QueryDescriptor MatchPhrase<TDocument>(Action<MatchPhraseQueryDescriptor<TDocument>> configure) => Set(configure, "match_phrase");
	public QueryDescriptor MatchPhrasePrefix(MatchPhrasePrefixQuery matchPhrasePrefixQuery) => Set(matchPhrasePrefixQuery, "match_phrase_prefix");
	public QueryDescriptor MatchPhrasePrefix(Action<MatchPhrasePrefixQueryDescriptor> configure) => Set(configure, "match_phrase_prefix");
	public QueryDescriptor MatchPhrasePrefix<TDocument>(Action<MatchPhrasePrefixQueryDescriptor<TDocument>> configure) => Set(configure, "match_phrase_prefix");
	public QueryDescriptor MoreLikeThis(MoreLikeThisQuery moreLikeThisQuery) => Set(moreLikeThisQuery, "more_like_this");
	public QueryDescriptor MoreLikeThis(Action<MoreLikeThisQueryDescriptor> configure) => Set(configure, "more_like_this");
	public QueryDescriptor MoreLikeThis<TDocument>(Action<MoreLikeThisQueryDescriptor<TDocument>> configure) => Set(configure, "more_like_this");
	public QueryDescriptor MultiMatch(MultiMatchQuery multiMatchQuery) => Set(multiMatchQuery, "multi_match");
	public QueryDescriptor MultiMatch(Action<MultiMatchQueryDescriptor> configure) => Set(configure, "multi_match");
	public QueryDescriptor MultiMatch<TDocument>(Action<MultiMatchQueryDescriptor<TDocument>> configure) => Set(configure, "multi_match");
	public QueryDescriptor Nested(NestedQuery nestedQuery) => Set(nestedQuery, "nested");
	public QueryDescriptor Nested(Action<NestedQueryDescriptor> configure) => Set(configure, "nested");
	public QueryDescriptor Nested<TDocument>(Action<NestedQueryDescriptor<TDocument>> configure) => Set(configure, "nested");
	public QueryDescriptor ParentId(ParentIdQuery parentIdQuery) => Set(parentIdQuery, "parent_id");
	public QueryDescriptor ParentId(Action<ParentIdQueryDescriptor> configure) => Set(configure, "parent_id");
	public QueryDescriptor Percolate(PercolateQuery percolateQuery) => Set(percolateQuery, "percolate");
	public QueryDescriptor Percolate(Action<PercolateQueryDescriptor> configure) => Set(configure, "percolate");
	public QueryDescriptor Percolate<TDocument>(Action<PercolateQueryDescriptor<TDocument>> configure) => Set(configure, "percolate");
	public QueryDescriptor Pinned(PinnedQuery pinnedQuery) => Set(pinnedQuery, "pinned");
	public QueryDescriptor Pinned(Action<PinnedQueryDescriptor> configure) => Set(configure, "pinned");
	public QueryDescriptor Pinned<TDocument>(Action<PinnedQueryDescriptor<TDocument>> configure) => Set(configure, "pinned");
	public QueryDescriptor Prefix(PrefixQuery prefixQuery) => Set(prefixQuery, "prefix");
	public QueryDescriptor Prefix(Action<PrefixQueryDescriptor> configure) => Set(configure, "prefix");
	public QueryDescriptor Prefix<TDocument>(Action<PrefixQueryDescriptor<TDocument>> configure) => Set(configure, "prefix");
	public QueryDescriptor QueryString(QueryStringQuery queryStringQuery) => Set(queryStringQuery, "query_string");
	public QueryDescriptor QueryString(Action<QueryStringQueryDescriptor> configure) => Set(configure, "query_string");
	public QueryDescriptor QueryString<TDocument>(Action<QueryStringQueryDescriptor<TDocument>> configure) => Set(configure, "query_string");
	public QueryDescriptor Range(RangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor Range(Action<RangeQueryDescriptor> configure) => Set(configure, "range");
	public QueryDescriptor Range<TDocument>(Action<RangeQueryDescriptor<TDocument>> configure) => Set(configure, "range");
	public QueryDescriptor RankFeature(RankFeatureQuery rankFeatureQuery) => Set(rankFeatureQuery, "rank_feature");
	public QueryDescriptor RankFeature(Action<RankFeatureQueryDescriptor> configure) => Set(configure, "rank_feature");
	public QueryDescriptor RankFeature<TDocument>(Action<RankFeatureQueryDescriptor<TDocument>> configure) => Set(configure, "rank_feature");
	public QueryDescriptor RawJson(Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawJsonQuery) => Set(rawJsonQuery, "raw_json");
	public QueryDescriptor Regexp(RegexpQuery regexpQuery) => Set(regexpQuery, "regexp");
	public QueryDescriptor Regexp(Action<RegexpQueryDescriptor> configure) => Set(configure, "regexp");
	public QueryDescriptor Regexp<TDocument>(Action<RegexpQueryDescriptor<TDocument>> configure) => Set(configure, "regexp");
	public QueryDescriptor RuleQuery(RuleQuery ruleQuery) => Set(ruleQuery, "rule_query");
	public QueryDescriptor RuleQuery(Action<RuleQueryDescriptor> configure) => Set(configure, "rule_query");
	public QueryDescriptor RuleQuery<TDocument>(Action<RuleQueryDescriptor<TDocument>> configure) => Set(configure, "rule_query");
	public QueryDescriptor Script(ScriptQuery scriptQuery) => Set(scriptQuery, "script");
	public QueryDescriptor Script(Action<ScriptQueryDescriptor> configure) => Set(configure, "script");
	public QueryDescriptor ScriptScore(ScriptScoreQuery scriptScoreQuery) => Set(scriptScoreQuery, "script_score");
	public QueryDescriptor ScriptScore(Action<ScriptScoreQueryDescriptor> configure) => Set(configure, "script_score");
	public QueryDescriptor ScriptScore<TDocument>(Action<ScriptScoreQueryDescriptor<TDocument>> configure) => Set(configure, "script_score");
	public QueryDescriptor SimpleQueryString(SimpleQueryStringQuery simpleQueryStringQuery) => Set(simpleQueryStringQuery, "simple_query_string");
	public QueryDescriptor SimpleQueryString(Action<SimpleQueryStringQueryDescriptor> configure) => Set(configure, "simple_query_string");
	public QueryDescriptor SimpleQueryString<TDocument>(Action<SimpleQueryStringQueryDescriptor<TDocument>> configure) => Set(configure, "simple_query_string");
	public QueryDescriptor SpanContaining(SpanContainingQuery spanContainingQuery) => Set(spanContainingQuery, "span_containing");
	public QueryDescriptor SpanContaining(Action<SpanContainingQueryDescriptor> configure) => Set(configure, "span_containing");
	public QueryDescriptor SpanContaining<TDocument>(Action<SpanContainingQueryDescriptor<TDocument>> configure) => Set(configure, "span_containing");
	public QueryDescriptor SpanFirst(SpanFirstQuery spanFirstQuery) => Set(spanFirstQuery, "span_first");
	public QueryDescriptor SpanFirst(Action<SpanFirstQueryDescriptor> configure) => Set(configure, "span_first");
	public QueryDescriptor SpanFirst<TDocument>(Action<SpanFirstQueryDescriptor<TDocument>> configure) => Set(configure, "span_first");
	public QueryDescriptor SpanMulti(SpanMultiTermQuery spanMultiTermQuery) => Set(spanMultiTermQuery, "span_multi");
	public QueryDescriptor SpanMulti(Action<SpanMultiTermQueryDescriptor> configure) => Set(configure, "span_multi");
	public QueryDescriptor SpanMulti<TDocument>(Action<SpanMultiTermQueryDescriptor<TDocument>> configure) => Set(configure, "span_multi");
	public QueryDescriptor SpanNear(SpanNearQuery spanNearQuery) => Set(spanNearQuery, "span_near");
	public QueryDescriptor SpanNear(Action<SpanNearQueryDescriptor> configure) => Set(configure, "span_near");
	public QueryDescriptor SpanNear<TDocument>(Action<SpanNearQueryDescriptor<TDocument>> configure) => Set(configure, "span_near");
	public QueryDescriptor SpanNot(SpanNotQuery spanNotQuery) => Set(spanNotQuery, "span_not");
	public QueryDescriptor SpanNot(Action<SpanNotQueryDescriptor> configure) => Set(configure, "span_not");
	public QueryDescriptor SpanNot<TDocument>(Action<SpanNotQueryDescriptor<TDocument>> configure) => Set(configure, "span_not");
	public QueryDescriptor SpanOr(SpanOrQuery spanOrQuery) => Set(spanOrQuery, "span_or");
	public QueryDescriptor SpanOr(Action<SpanOrQueryDescriptor> configure) => Set(configure, "span_or");
	public QueryDescriptor SpanOr<TDocument>(Action<SpanOrQueryDescriptor<TDocument>> configure) => Set(configure, "span_or");
	public QueryDescriptor SpanTerm(SpanTermQuery spanTermQuery) => Set(spanTermQuery, "span_term");
	public QueryDescriptor SpanTerm(Action<SpanTermQueryDescriptor> configure) => Set(configure, "span_term");
	public QueryDescriptor SpanTerm<TDocument>(Action<SpanTermQueryDescriptor<TDocument>> configure) => Set(configure, "span_term");
	public QueryDescriptor SpanWithin(SpanWithinQuery spanWithinQuery) => Set(spanWithinQuery, "span_within");
	public QueryDescriptor SpanWithin(Action<SpanWithinQueryDescriptor> configure) => Set(configure, "span_within");
	public QueryDescriptor SpanWithin<TDocument>(Action<SpanWithinQueryDescriptor<TDocument>> configure) => Set(configure, "span_within");
	public QueryDescriptor Term(TermQuery termQuery) => Set(termQuery, "term");
	public QueryDescriptor Term(Action<TermQueryDescriptor> configure) => Set(configure, "term");
	public QueryDescriptor Term<TDocument>(Action<TermQueryDescriptor<TDocument>> configure) => Set(configure, "term");
	public QueryDescriptor Terms(TermsQuery termsQuery) => Set(termsQuery, "terms");
	public QueryDescriptor Terms(Action<TermsQueryDescriptor> configure) => Set(configure, "terms");
	public QueryDescriptor Terms<TDocument>(Action<TermsQueryDescriptor<TDocument>> configure) => Set(configure, "terms");
	public QueryDescriptor TermsSet(TermsSetQuery termsSetQuery) => Set(termsSetQuery, "terms_set");
	public QueryDescriptor TermsSet(Action<TermsSetQueryDescriptor> configure) => Set(configure, "terms_set");
	public QueryDescriptor TermsSet<TDocument>(Action<TermsSetQueryDescriptor<TDocument>> configure) => Set(configure, "terms_set");
	public QueryDescriptor TextExpansion(TextExpansionQuery textExpansionQuery) => Set(textExpansionQuery, "text_expansion");
	public QueryDescriptor TextExpansion(Action<TextExpansionQueryDescriptor> configure) => Set(configure, "text_expansion");
	public QueryDescriptor TextExpansion<TDocument>(Action<TextExpansionQueryDescriptor<TDocument>> configure) => Set(configure, "text_expansion");
	public QueryDescriptor Wildcard(WildcardQuery wildcardQuery) => Set(wildcardQuery, "wildcard");
	public QueryDescriptor Wildcard(Action<WildcardQueryDescriptor> configure) => Set(configure, "wildcard");
	public QueryDescriptor Wildcard<TDocument>(Action<WildcardQueryDescriptor<TDocument>> configure) => Set(configure, "wildcard");
	public QueryDescriptor Wrapper(WrapperQuery wrapperQuery) => Set(wrapperQuery, "wrapper");
	public QueryDescriptor Wrapper(Action<WrapperQueryDescriptor> configure) => Set(configure, "wrapper");

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		if (!ContainsVariant)
		{
			writer.WriteNullValue();
			return;
		}

		if (ContainedVariantName == "raw_json")
		{
			writer.WriteRawValue(((RawJsonQuery)Variant).Raw);
			return;
		}

		writer.WriteStartObject();
		writer.WritePropertyName(ContainedVariantName);
		if (Variant is not null)
		{
			JsonSerializer.Serialize(writer, Variant, Variant.GetType(), options);
			writer.WriteEndObject();
			return;
		}

		JsonSerializer.Serialize(writer, Descriptor, Descriptor.GetType(), options);
		writer.WriteEndObject();
	}
}